﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Auth_Ativos : System.Web.UI.UserControl, IViewStatePersist
{
	protected void Page_Load(object sender, EventArgs e)
	{

	}
	protected void lvAtivo_ItemEditing(object sender, ListViewEditEventArgs e)
	{
		this.lvAtivo.SelectedIndex = e.NewEditIndex;
	}
	protected void lvAtivo_ItemUpdated(object sender, ListViewUpdatedEventArgs e)
	{
		foreach (DataListItem item in this.dlCampoAtivo.Items)
		{
			this.dlCampoAtivo.SelectedIndex = item.ItemIndex;
			this.CampoAtivo.Update();
		}
		this.dlCampoAtivo.SelectedIndex = -1;
		this.lvAtivo.SelectedIndex = -1;
	}
	protected void lvAtivo_ItemCanceling(object sender, ListViewCancelEventArgs e)
	{
		this.lvAtivo.SelectedIndex = -1;
	}
	protected void CampoAtivo_Updating(object sender, ObjectDataSourceMethodEventArgs e)
	{
		HiddenField AtivoIdHiddenField = this.dlCampoAtivo.SelectedItem.FindControl("AtivoIdHiddenField") as HiddenField;
		HiddenField CampoIdHiddenField = this.dlCampoAtivo.SelectedItem.FindControl("CampoIdHiddenField") as HiddenField;
		HiddenField CommandNameHiddenField = this.dlCampoAtivo.SelectedItem.FindControl("CommandNameHiddenField") as HiddenField;
		TextBox CampoAtivoValorTextBox = this.dlCampoAtivo.SelectedItem.FindControl("CampoAtivoValorTextBox") as TextBox;
		e.InputParameters["CommandName"] = CommandNameHiddenField.Value;
		e.InputParameters["CampoAtivoValor"] = CampoAtivoValorTextBox.Text;
		e.InputParameters["Original_CampoId"] = CampoIdHiddenField.Value;
		e.InputParameters["Original_AtivoId"] = AtivoIdHiddenField.Value;


	}
	protected void lvAtivo_ItemInserting(object sender, ListViewInsertEventArgs e)
	{
		DropDownList TipoAtivoIdDropDownList = e.Item.FindControl("TipoAtivoIdDropDownList") as DropDownList;
		e.Values["TipoAtivoId"] = TipoAtivoIdDropDownList.SelectedValue;

		DropDownList FabricanteAtivoIdDropDownList = e.Item.FindControl("FabricanteAtivoIdDropDownList") as DropDownList;
		e.Values["FabricanteAtivoId"] = FabricanteAtivoIdDropDownList.SelectedValue;
		e.Values["AtivoRFID"] = e.Values["AtivoRFID"].ToString().PadLeft(8, '0');
	}

	#region IViewStatePersist Members

	public new object SaveViewState()
	{
		return base.SaveViewState();
	}

	public new void LoadViewState(object savedState)
	{
		base.LoadViewState(savedState);
	}

	#endregion
	protected void lvAtivo_ItemUpdating(object sender, ListViewUpdateEventArgs e)
	{
		e.NewValues["AtivoRFID"] = e.NewValues["AtivoRFID"].ToString().PadLeft(8, '0');
	}
}
